from channels.routing import ProtocolTypeRouter,URLRouter
from django.urls import re_path
from components.deploy.k8s_release.k8s_host_deploy_info import K8sHostDeployInfo
from components.deploy.soft_release.soft_deploy_info import SoftDeployInfo
from components.kubernetes.deployments.download_event import DownloadEvent

application = ProtocolTypeRouter({
    'websocket':URLRouter([
        re_path(r'^soft_deploy_info$', SoftDeployInfo()),
        re_path(r'^k8s_host_deploy_info$', K8sHostDeployInfo()),
        re_path(r'^download_event$', DownloadEvent())
    ])
})


"""
from channels.generic.websocket import AsyncJsonWebsocketConsumer
from table.models import Table
 
 
class TableConsumer(AsyncJsonWebsocketConsumer):
    table = None
 
    async def connect(self):
        self.table = 'table_{}'.format(self.scope['url_route']['kwargs']['table_id'])
        # Join room group
        await self.channel_layer.group_add(self.table, self.channel_name)
        await self.accept()
 
    async def disconnect(self, close_code):
        # Leave room group
        await self.channel_layer.group_discard(self.table, self.channel_name)
 
    # Receive message from WebSocket
    async def receive_json(self, content, **kwargs):
        # Send message to room group
        await self.channel_layer.group_send(self.table, {'type': 'message', 'message': content})
 
    # Receive message from room group
    async def message(self, event):
        message = event['message']
        # Send message to WebSocket
        await self.send_json(message)
"""